package com.daiyang.campus_lucky_draw.common.handler;

import com.daiyang.campus_lucky_draw.common.error.GlobalErrorCodeConstants;
import com.daiyang.campus_lucky_draw.common.exception.ControllerException;
import com.daiyang.campus_lucky_draw.common.exception.ServiceException;
import com.daiyang.campus_lucky_draw.common.result.CommonReslut;
import com.daiyang.campus_lucky_draw.contreller.param.UserRegisterParam;
import com.daiyang.campus_lucky_draw.service.dto.UserRegisterDTO;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    private Logger logger
            = LoggerFactory.getLogger(GlobalExceptionHandler.class);


    @ExceptionHandler(value =  Exception.class)
    public CommonReslut<?> exception(Exception e) {
        logger.error("服务错误:", e);
        return CommonReslut.error(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),e.getMessage());
    }
    @ExceptionHandler(value = ServiceException.class)
    public CommonReslut<?> serviceException(ServiceException serviceException) {

        return CommonReslut.error(serviceException.getCode(),serviceException.getMessage());
    }
    @ExceptionHandler(value = ControllerException.class)
    public CommonReslut<?> controllerException(ControllerException controllerException) {
        return CommonReslut.error(controllerException.getCode(),controllerException.getMessage());
    }
}
